package com.example.colorpickdemo.util;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.widget.Toast;

import com.example.colorpickdemo.BuildConfig;
import com.example.colorpickdemo.runtime.RT;


/**
 * Created by daiguangtao on 2020/05/30.
 */
public class ToastUtil {
//    public static List<String> list = new ArrayList<String>();

    public static void showtoast(String text) {
        if (!PhoneUtil.isRunningForeground(RT.application)){
            return;
        }
        ToastUtils.showShort(text);
//        Toast.makeText(RT.application, text, Toast.LENGTH_SHORT).show();
    }
    public static void cancel() {
        ToastUtils.cancel();
    }

    public static void showDebugtoast(String text) {
        if (BuildConfig.DEBUG) {
            Toast.makeText(RT.application, text, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * Log tag ：ToastUtil
     */
    private static final String LOG_TAG = "ToastUtil";

    private static Toast sToast;

    private static final Handler sHandler = new Handler();

    private static final Runnable sRun = new Runnable() {
        public void run() {
            try {
                sToast.cancel();
                // toast隐藏后，将其置为null
                sToast = null;
            } catch (Exception e) {

            }
        }
    };

    /**
     * 短时间显示Toast
     *
     * @param context context
     * @param msg     需要显示的信息
     */
    public static void showShortToast(Context context, String msg) {
        showToast(context.getApplicationContext(), msg, Toast.LENGTH_SHORT, 1500);

    }

    /**
     * 长时间显示Toast
     *
     * @param context context
     * @param msg     需要显示的信息
     */
    public static void showLongToast(Context context, String msg) {
        showToast(context.getApplicationContext(), msg, Toast.LENGTH_LONG, 3000);

    }

    /**
     * 显示toast
     *
     * @param appContext  appContext
     * @param msg         需要显示的信息
     * @param duration    显示时间
     * @param delayMillis 延迟关闭时间
     */
    private static void showToast(Context appContext, String msg, int duration, int delayMillis) {
        LayoutInflater inflater = (LayoutInflater) appContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
}
